home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / include / php / Zend / zend.h < prev   
Encoding:
C/C++ Source or Header  |  2001-01-03  |  12.6 KB  |  460 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.txt.                                |
  11.    | If you did not receive a copy of the Zend license and are unable to  |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@zend.com so we can mail you a copy immediately.              |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Zeev Suraski <zeev@zend.com>                                |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20.  
  21. #ifndef ZEND_H
  22. #define ZEND_H
  23.  
  24. #define ZEND_VERSION "1.0.4"
  25.  
  26. #ifdef __cplusplus
  27. #define BEGIN_EXTERN_C() extern "C" {
  28. #define END_EXTERN_C() }
  29. #else
  30. #define BEGIN_EXTERN_C()
  31. #define END_EXTERN_C()
  32. #endif
  33.  
  34. #include <stdio.h>
  35.  
  36. /*
  37.  * general definitions
  38.  */
  39.  
  40. #ifdef ZEND_WIN32
  41. # include "zend_config.w32.h"
  42. #else
  43. # include "zend_config.h"
  44. #endif
  45.  
  46. /* all HAVE_XXX test have to be after the include of zend_config above */
  47.  
  48. #ifdef HAVE_UNIX_H
  49. # include <unix.h>
  50. #endif
  51.  
  52. #ifdef HAVE_STDARG_H
  53. # include <stdarg.h>
  54. #endif
  55.  
  56. #ifdef HAVE_DLFCN_H
  57. # include <dlfcn.h>
  58. #endif
  59.  
  60. #if defined(HAVE_LIBDL)
  61.  
  62. # ifndef RTLD_LAZY
  63. #  define RTLD_LAZY 1    /* Solaris 1, FreeBSD's (2.1.7.1 and older) */
  64. # endif
  65.  
  66. # ifndef RTLD_GLOBAL
  67. #  define RTLD_GLOBAL 0
  68. # endif
  69.  
  70. # define DL_LOAD(libname)            dlopen(libname, RTLD_LAZY | RTLD_GLOBAL)
  71. # define DL_UNLOAD                    dlclose
  72. # define DL_FETCH_SYMBOL            dlsym
  73. # define DL_HANDLE                    void *
  74. # define ZEND_EXTENSIONS_SUPPORT    1
  75. #elif defined(ZEND_WIN32)
  76. # define DL_LOAD(libname)            LoadLibrary(libname)
  77. # define DL_FETCH_SYMBOL            GetProcAddress
  78. # define DL_UNLOAD                    FreeLibrary
  79. # define DL_HANDLE                    HMODULE
  80. # define ZEND_EXTENSIONS_SUPPORT    1
  81. #else
  82. # define DL_HANDLE                    void *
  83. # define ZEND_EXTENSIONS_SUPPORT    0
  84. #endif
  85.  
  86. #if HAVE_ALLOCA_H
  87. # include <alloca.h>
  88. #endif
  89.  
  90. #if (HAVE_ALLOCA || (defined (__GNUC__) && __GNUC__ >= 2)) && !(defined(ZTS) && defined(ZEND_WIN32))
  91. # define do_alloca(p) alloca(p)
  92. # define free_alloca(p)
  93. #else
  94. # define do_alloca(p)        emalloc(p)
  95. # define free_alloca(p)    efree(p)
  96. #endif
  97.  
  98. #if ZEND_DEBUG
  99. #define ZEND_FILE_LINE_D                char *__zend_filename, uint __zend_lineno
  100. #define ZEND_FILE_LINE_DC                , ZEND_FILE_LINE_D
  101. #define ZEND_FILE_LINE_ORIG_D            char *__zend_orig_filename, uint __zend_orig_lineno
  102. #define ZEND_FILE_LINE_ORIG_DC            , ZEND_FILE_LINE_ORIG_D
  103. #define ZEND_FILE_LINE_RELAY_C            __zend_filename, __zend_lineno
  104. #define ZEND_FILE_LINE_RELAY_CC            , ZEND_FILE_LINE_RELAY_C
  105. #define ZEND_FILE_LINE_C                __FILE__, __LINE__
  106. #define ZEND_FILE_LINE_CC                , ZEND_FILE_LINE_C
  107. #define ZEND_FILE_LINE_EMPTY_C            NULL, 0
  108. #define ZEND_FILE_LINE_EMPTY_CC            , ZEND_FILE_LINE_EMPTY_C
  109. #define ZEND_FILE_LINE_ORIG_RELAY_C        __zend_orig_filename, __zend_orig_lineno
  110. #define ZEND_FILE_LINE_ORIG_RELAY_CC    , ZEND_FILE_LINE_ORIG_RELAY_C
  111. #else
  112. #define ZEND_FILE_LINE_D
  113. #define ZEND_FILE_LINE_DC
  114. #define ZEND_FILE_LINE_ORIG_D
  115. #define ZEND_FILE_LINE_ORIG_DC
  116. #define ZEND_FILE_LINE_RELAY_C
  117. #define ZEND_FILE_LINE_RELAY_CC
  118. #define ZEND_FILE_LINE_C
  119. #define ZEND_FILE_LINE_CC
  120. #define ZEND_FILE_LINE_EMPTY_C
  121. #define ZEND_FILE_LINE_EMPTY_CC
  122. #define ZEND_FILE_LINE_ORIG_RELAY_C
  123. #define ZEND_FILE_LINE_ORIG_RELAY_CC
  124. #endif    /* ZEND_DEBUG */
  125.  
  126. #ifdef ZTS
  127. #define ZTS_V 1
  128. #else
  129. #define ZTS_V 0
  130. #endif
  131.  
  132. #include "zend_errors.h"
  133. #include "zend_alloc.h"
  134.  
  135. typedef unsigned char zend_bool;
  136. typedef unsigned char zend_uchar;
  137. typedef unsigned int zend_uint;
  138. typedef unsigned long zend_ulong;
  139. typedef unsigned short zend_ushort;
  140.  
  141. #undef SUCCESS
  142. #undef FAILURE
  143. #define SUCCESS 0
  144. #define FAILURE -1                /* this MUST stay a negative number, or it may affect functions! */
  145.  
  146.  
  147. #include "zend_hash.h"
  148. #include "zend_llist.h"
  149.  
  150. #define INTERNAL_FUNCTION_PARAMETERS int ht, zval *return_value, zval *this_ptr, int return_value_used ELS_DC
  151. #define INTERNAL_FUNCTION_PARAM_PASSTHRU ht, return_value, this_ptr, return_value_used ELS_CC
  152.  
  153. /*
  154.  * zval
  155.  */
  156. typedef struct _zval_struct zval;
  157. typedef struct _zend_class_entry zend_class_entry;
  158.  
  159. typedef union _zvalue_value {
  160.     long lval;                    /* long value */
  161.     double dval;                /* double value */
  162.     struct {
  163.         char *val;
  164.         int len;
  165.     } str;
  166.     HashTable *ht;                /* hash table value */
  167.     struct {
  168.         zend_class_entry *ce;
  169.         HashTable *properties;
  170.     } obj;
  171. } zvalue_value;
  172.  
  173.  
  174. struct _zval_struct {
  175.     /* Variable information */
  176.     zvalue_value value;        /* value */
  177.     zend_uchar type;    /* active type */
  178.     zend_uchar is_ref;
  179.     zend_ushort refcount;
  180. };
  181.  
  182.  
  183.  
  184. typedef struct _zend_function_entry {
  185.     char *fname;
  186.     void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
  187.     unsigned char *func_arg_types;
  188. } zend_function_entry;
  189.  
  190.  
  191. typedef struct _zend_property_reference {
  192.     int type;  /* read, write or r/w */
  193.     zval *object;
  194.     zend_llist *elements_list;
  195. } zend_property_reference;
  196.  
  197.  
  198.  
  199. typedef struct _zend_overloaded_element {
  200.     int type;        /* array offset or object proprety */
  201.     zval element;
  202. } zend_overloaded_element;
  203.  
  204. /* excpt.h on Digital Unix 4.0 defines function_table */
  205. #undef function_table
  206.  
  207. struct _zend_class_entry {
  208.     char type;
  209.     char *name;
  210.     uint name_length;
  211.     struct _zend_class_entry *parent; 
  212.     int *refcount;
  213.     zend_bool constants_updated;
  214.  
  215.     HashTable function_table;
  216.     HashTable default_properties;
  217.     zend_function_entry *builtin_functions;
  218.  
  219.     /* handlers */
  220.     void (*handle_function_call)(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference);
  221.     zval (*handle_property_get)(zend_property_reference *property_reference);
  222.     int (*handle_property_set)(zend_property_reference *property_reference, zval *value);
  223. };
  224.  
  225.  
  226.  
  227. typedef struct _zend_utility_functions {
  228.     void (*error_function)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
  229.     int (*printf_function)(const char *format, ...);
  230.     int (*write_function)(const char *str, uint str_length);
  231.     FILE *(*fopen_function)(const char *filename, char **opened_path);
  232.     void (*message_handler)(long message, void *data);
  233.     void (*block_interruptions)(void);
  234.     void (*unblock_interruptions)(void);
  235.     int (*get_ini_entry)(char *name, uint name_length, zval *contents);
  236.     void (*ticks_function)(int ticks);
  237. } zend_utility_functions;
  238.  
  239.         
  240. typedef struct _zend_utility_values {
  241.     char *import_use_extension;
  242.     uint import_use_extension_length;
  243. } zend_utility_values;
  244.  
  245.  
  246. typedef int (*zend_write_func_t)(const char *str, uint str_length);
  247.  
  248.  
  249. #undef MIN
  250. #undef MAX
  251. #define MAX(a,b)  (((a)>(b))?(a):(b))
  252. #define MIN(a,b)  (((a)<(b))?(a):(b))
  253. #define ZEND_STRL(str)        (str), (sizeof(str)-1)
  254. #define ZEND_STRS(str)        (str), (sizeof(str)
  255. #define ZEND_NORMALIZE_BOOL(n)            \
  256.     ((n) ? (((n)>0) ? 1 : -1) : 0)
  257.  
  258.  
  259. /* data types */
  260. #define IS_NULL        0
  261. #define IS_LONG        1
  262. #define IS_DOUBLE    2
  263. #define IS_STRING    3
  264. #define IS_ARRAY    4
  265. #define IS_OBJECT    5
  266. #define IS_BOOL        6
  267. #define IS_RESOURCE    7
  268. #define IS_CONSTANT    8
  269. #define IS_CONSTANT_ARRAY    9
  270.  
  271. /* Special data type to temporarily mark large numbers */
  272. #define FLAG_IS_BC    10 /* for parser internal use only */
  273.  
  274. /* overloaded elements data types */
  275. #define OE_IS_ARRAY    (1<<0)
  276. #define OE_IS_OBJECT    (1<<1)
  277. #define OE_IS_METHOD    (1<<2)
  278.  
  279.  
  280. /* Argument passing types */
  281. #define BYREF_NONE 0
  282. #define BYREF_FORCE 1
  283. #define BYREF_ALLOW 2
  284. #define BYREF_FORCE_REST 3
  285.  
  286. int zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions);
  287. void zend_shutdown(void);
  288.  
  289. void zend_set_utility_values(zend_utility_values *utility_values);
  290. BEGIN_EXTERN_C()
  291. ZEND_API void zend_bailout(void);
  292. END_EXTERN_C()
  293. ZEND_API char *get_zend_version(void);
  294.  
  295. ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy);
  296. ZEND_API int zend_print_zval(zval *expr, int indent);
  297. ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent);
  298. ZEND_API void zend_print_zval_r(zval *expr, int indent);
  299. ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent);
  300.  
  301. ZEND_API void zend_output_debug_string(zend_bool trigger_break, char *format, ...);
  302. #if ZEND_DEBUG
  303. #define Z_DBG(expr)        (expr)
  304. #else
  305. #define    Z_DBG(expr)
  306. #endif
  307.  
  308. ZEND_API extern char *empty_string;
  309.  
  310. #define STR_FREE(ptr) if (ptr && ptr!=empty_string) { efree(ptr); }
  311. #define STR_FREE_REL(ptr) if (ptr && ptr!=empty_string) { efree_rel(ptr); }
  312.  
  313. #define STR_REALLOC(ptr, size)                                        \
  314.     if (ptr!=empty_string) {                                        \
  315.         ptr = (char *) erealloc(ptr, size);                            \
  316.     } else {                                                        \
  317.         ptr = (char *) emalloc(size);                                \
  318.         memset(ptr, 0, size);                                        \
  319.     }
  320.  
  321. /* output support */
  322. #define ZEND_WRITE(str, str_len)        zend_write((str), (str_len))
  323. #define ZEND_PUTS(str)                    zend_write((str), strlen((str)))
  324. #define ZEND_PUTC(c)                    zend_write(&(c), 1), (c)
  325.  
  326.  
  327. BEGIN_EXTERN_C()
  328. extern ZEND_API int (*zend_printf)(const char *format, ...);
  329. extern ZEND_API zend_write_func_t zend_write;
  330. extern ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
  331. extern ZEND_API void (*zend_block_interruptions)(void);
  332. extern ZEND_API void (*zend_unblock_interruptions)(void);
  333. extern ZEND_API void (*zend_ticks_function)(int ticks);
  334. extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
  335.  
  336.  
  337. ZEND_API void zend_error(int type, const char *format, ...);
  338.  
  339. void zenderror(char *error);
  340.  
  341. extern ZEND_API zend_class_entry zend_standard_class_def;
  342. extern zend_utility_values zend_uv;
  343. extern ZEND_API zval zval_used_for_init;
  344.  
  345. END_EXTERN_C()
  346.  
  347. #define ZEND_UV(name) (zend_uv.name)
  348.  
  349.  
  350. #define HANDLE_BLOCK_INTERRUPTIONS()        if (zend_block_interruptions) { zend_block_interruptions(); }
  351. #define HANDLE_UNBLOCK_INTERRUPTIONS()        if (zend_unblock_interruptions) { zend_unblock_interruptions(); }
  352.  
  353. BEGIN_EXTERN_C()
  354. ZEND_API void zend_message_dispatcher(long message, void *data);
  355. END_EXTERN_C()
  356.  
  357. ZEND_API int zend_get_ini_entry(char *name, uint name_length, zval *contents);
  358.  
  359.  
  360. /* Messages for applications of Zend */
  361. #define ZMSG_FAILED_INCLUDE_FOPEN        1L
  362. #define ZMSG_FAILED_REQUIRE_FOPEN        2L
  363. #define ZMSG_FAILED_HIGHLIGHT_FOPEN        3L
  364. #define ZMSG_MEMORY_LEAK_DETECTED        4L
  365. #define ZMSG_MEMORY_LEAK_REPEATED        5L
  366. #define ZMSG_LOG_SCRIPT_NAME            6L
  367.  
  368.  
  369. #define ZVAL_ADDREF(pz)        (++(pz)->refcount)
  370. #define ZVAL_DELREF(pz)        (--(pz)->refcount)
  371. #define ZVAL_REFCOUNT(pz)    ((pz)->refcount)
  372.  
  373. #define INIT_PZVAL(z)        \
  374.     (z)->refcount = 1;        \
  375.     (z)->is_ref = 0;    
  376.  
  377. #define INIT_ZVAL(z) z = zval_used_for_init;
  378.  
  379. #define ALLOC_INIT_ZVAL(zp)                        \
  380.     ALLOC_ZVAL(zp);        \
  381.     INIT_ZVAL(*zp);
  382.  
  383. #define MAKE_STD_ZVAL(zv)                 \
  384.     ALLOC_ZVAL(zv); \
  385.     INIT_PZVAL(zv);
  386.  
  387. #define PZVAL_IS_REF(z)        ((z)->is_ref)
  388.  
  389. #define SEPARATE_ZVAL(ppzv)                                    \
  390.     {                                                        \
  391.         zval *orig_ptr = *(ppzv);                            \
  392.                                                             \
  393.         if (orig_ptr->refcount>1) {                            \
  394.             orig_ptr->refcount--;                            \
  395.             ALLOC_ZVAL(*(ppzv));                            \
  396.             **(ppzv) = *orig_ptr;                            \
  397.             zval_copy_ctor(*(ppzv));                        \
  398.             (*(ppzv))->refcount=1;                            \
  399.             (*(ppzv))->is_ref = 0;                            \
  400.         }                                                    \
  401.     }
  402.  
  403. #define SEPARATE_ZVAL_IF_NOT_REF(ppzv)        \
  404.     if (!PZVAL_IS_REF(*ppzv)) {                \
  405.         SEPARATE_ZVAL(ppzv);                \
  406.     }
  407.  
  408. #define SEPARATE_ZVAL_TO_MAKE_IS_REF(ppzv)    \
  409.     if (!PZVAL_IS_REF(*ppzv)) {                \
  410.         SEPARATE_ZVAL(ppzv);                \
  411.         (*(ppzv))->is_ref = 1;                \
  412.     }
  413.  
  414. #define COPY_PZVAL_TO_ZVAL(zv, pzv)            \
  415.     (zv) = *(pzv);                            \
  416.     if ((pzv)->refcount>1) {                \
  417.         zval_copy_ctor(&(zv));                \
  418.         (pzv)->refcount--;                    \
  419.     } else {                                \
  420.         FREE_ZVAL(pzv);                        \
  421.     }                                        \
  422.     INIT_PZVAL(&(zv));
  423.  
  424. #define REPLACE_ZVAL_VALUE(ppzv_dest,pzv_src,copy) {    \
  425.     int is_ref,refcount;                        \
  426.                                                 \
  427.     SEPARATE_ZVAL_IF_NOT_REF(ppzv_dest);        \
  428.     is_ref = (*ppzv_dest)->is_ref;                \
  429.     refcount = (*ppzv_dest)->refcount;            \
  430.     zval_dtor(*ppzv_dest);                        \
  431.     **ppzv_dest = *pzv_src;                        \
  432.     if(copy) {                                  \
  433.         zval_copy_ctor(*ppzv_dest);                \
  434.     }                                            \
  435.     (*ppzv_dest)->is_ref = is_ref;                \
  436.     (*ppzv_dest)->refcount = refcount;            \
  437. }
  438.  
  439. #define ZEND_MAX_RESERVED_RESOURCES    2
  440.  
  441. #ifdef ZEND_WIN32
  442. /* Only use this macro if you know for sure that all of the switches values
  443.    are covered by its case statements */
  444. #define EMPTY_SWITCH_DEFAULT_CASE() \
  445.             default:                \
  446.                 __assume(0);        \
  447.                 break;
  448. #else
  449. #define EMPTY_SWITCH_DEFAULT_CASE()
  450. #endif
  451.  
  452. #endif /* ZEND_H */
  453.  
  454. /*
  455.  * Local variables:
  456.  * tab-width: 4
  457.  * c-basic-offset: 4
  458.  * End:
  459.  */
  460.